#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
安装脚本
"""

import subprocess
import sys
import os
from pathlib import Path


def install_requirements():
    """安装依赖包"""
    print("正在安装依赖包...")
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
        print("依赖包安装完成")
        return True
    except subprocess.CalledProcessError as e:
        print(f"依赖包安装失败: {e}")
        return False


def create_directories():
    """创建必要的目录"""
    print("正在创建目录...")
    directories = [
        "logs",
        "data",
        "temp"
    ]
    
    for directory in directories:
        Path(directory).mkdir(exist_ok=True)
        print(f"创建目录: {directory}")


def check_python_version():
    """检查Python版本"""
    if sys.version_info < (3, 7):
        print("错误: 需要Python 3.7或更高版本")
        return False
    print(f"Python版本: {sys.version}")
    return True


def main():
    """主函数"""
    print("XBot客户端安装程序")
    print("=" * 50)
    
    # 检查Python版本
    if not check_python_version():
        return
    
    # 创建目录
    create_directories()
    
    # 安装依赖
    if not install_requirements():
        print("安装失败，请检查网络连接或手动安装依赖")
        return
    
    print("\n安装完成！")
    print("=" * 50)
    print("使用方法:")
    print("1. 运行程序: python main.py")
    print("2. 测试插件: python test_plugins.py")
    print("3. 查看日志: tail -f app.log")
    print("\n更多信息请查看 README.md")


if __name__ == "__main__":
    main() 